/*
 * Threads.c
 *
 *  Created on: Apr 15, 2013
 *      Author: BAYRAMOV Matin
 */
#include <stdio.h>
#include <stdlib.h>

#include <sys/time.h>
#include <pthread.h>

struct timeval tv;

// Task A
void * taskA();

// Task B
void * taskB();

// Task C - main task
int main () {

	printf("\n===THREADS===\n");

	// Thread declaration
	pthread_t threadA, threadB;

	// Create threads
	pthread_create(&threadA, NULL, taskA, NULL);
	pthread_create(&threadB, NULL, taskB, NULL);

	// This is another task in main
	gettimeofday(&tv,NULL);
	printf("\nTHIRD		:%f", (double) tv.tv_usec);

	// Wait to end of threads
	pthread_join(threadA, NULL);
	pthread_join(threadB, NULL);

	gettimeofday(&tv,NULL);
	printf("\n\nFOURTH		:%f", (double) tv.tv_usec);

	return 0;
}

// Task A
void * taskA() {
	gettimeofday(&tv,NULL);
	printf("\nFIRST		:%f", (double) tv.tv_usec);
	return 0;
}

// Task B
void * taskB() {
	gettimeofday(&tv,NULL);
	printf("\nSECOND		:%f", (double) tv.tv_usec);
	return 0;
}
